package org.video.mine.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.databinding.ViewDataBinding;
import androidx.recyclerview.widget.RecyclerView;

import org.video.mine.GlobalStr;
import org.video.mine.R;
import org.video.mine.databinding.LoadedLayoutBinding;
import org.video.mine.entity.LoadedEntity;
import org.video.mine.model.ClickModel;

import java.util.ArrayList;
import java.util.List;

public class LoadingAdapter extends RecyclerView.Adapter<GlobalStr.ViewHolder> {

    private List<LoadedEntity> loadedEntities;
    private Context context;
    private boolean isLoading;

    public LoadingAdapter(List<LoadedEntity> loadedEntities, Context context, boolean isLoading) {
        this.loadedEntities = loadedEntities;
        this.context = context;
        this.isLoading = isLoading;
    }

    @NonNull
    @Override
    public GlobalStr.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ViewDataBinding inflate = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.loaded_layout, parent, false);
        return new GlobalStr.ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull GlobalStr.ViewHolder holder, int position) {
        LoadedEntity loadedEntity = loadedEntities.get(position);
        LoadedLayoutBinding binding = ((LoadedLayoutBinding)holder.getTitleBinding());
        binding.setLoadinfo(loadedEntity);
        binding.setConetxt(context);
        binding.setClick(new ClickModel());
        binding.setIsLoading(isLoading);
    }

    @Override
    public int getItemCount() {
        return loadedEntities.size();
    }
}
